package com.ccl.iot.asynctask;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;

public abstract class CustomTask<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> {
    protected Context mContext;
    protected ProgressDialog progressDialog;

    private String mMessage;

    public CustomTask(Context context, String message) {
        mContext = context;
        mMessage = message;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        if (mMessage != null) {
            progressDialog = new ProgressDialog(mContext, ProgressDialog.THEME_DEVICE_DEFAULT_LIGHT);
            progressDialog.setMessage(mMessage);
            progressDialog.show();
        }
    }

    @Override
    protected void onPostExecute(Result result) {
        super.onPostExecute(result);
        if (progressDialog != null) {
            progressDialog.dismiss();
        }
    }
}